#include "git-compat-util.h"
#include "noop.h"
#include "../commit.h"
#include "../fetch-negotiator.h"

/**
 * Notify the fetch negotiator that the given commits are known by both
 * sides.
 *
 * Since the noop negotiator does not actually fetch any commits, this
 * function does nothing.
 */
static void known_common(struct fetch_negotiator *n UNUSED,
			 struct commit *c UNUSED)
{
	/* do nothing */
}

/**
 * Add the tip commit from the fetch negotiator.
 *
 * This is a no-op since the noop negotiator does not actually fetch any
 * commits.
 *
 * @param n the fetch negotiator
 * @param c the commit (unused)
 */
static void add_tip(struct fetch_negotiator *n UNUSED,
		    struct commit *c UNUSED)
{
	/* do nothing */
}

/**
 * Get the next commit from the fetch negotiator.
 *
 * @param n the fetch negotiator
 * @return the next commit, or NULL if there are no more commits
 */
static const struct object_id *next(struct fetch_negotiator *n UNUSED)
{
	return NULL;
}

/**
 * Acknowledge receipt of a commit from the fetch negotiator.
 *
 * Since the noop negotiator does not emit any commits, this is a no-op.
 * If called, it likely indicates a bug.
 */
static int ack(struct fetch_negotiator *n UNUSED, struct commit *c UNUSED)
{
	/*
	 * This negotiator does not emit any commits, so there is no commit to
	 * be acknowledged. If there is any ack, there is a bug.
	 */
	BUG("ack with noop negotiator, which does not emit any commits");
	return 0;
}

/**
 * Release resources associated with noop fetch negotiator.
 *
 * This is a no-op since the noop negotiator does not allocate any resources.
 */
static void release(struct fetch_negotiator *n UNUSED)
{
	/* nothing to release */
}

/**
 * Initialize a noop fetch negotiator.
 *
 * This sets up the callbacks for a noop fetch negotiator that does not
 * actually negotiate any commits during fetching. It is used for testing.
 *
 * @param negotiator the fetch negotiator to initialize
 */
void noop_negotiator_init(struct fetch_negotiator *negotiator)
{
	negotiator->known_common = known_common;
	negotiator->add_tip = add_tip;
	negotiator->next = next;
	negotiator->ack = ack;
	negotiator->release = release;
	negotiator->data = NULL;
}
